﻿@page "/Users/UserView"
@inherits _BaseView

<MaanfeeDashboardPage>
    <MaanfeeDashboardPageHeader PageTitle="@DashboardResource.StringUser" />

    <MudPaper>
        <MudToolBar>
            <MudText Color="Color.Primary">
                @DashboardResource.StringUser
            </MudText>
            <MudSpacer />
            <MudIconButton Disabled="@(!_PermissionCreate)" OnClick="@(() => OpenCrudateDialog("0"))" Color="Color.Primary" Icon="@Icons.Material.Outlined.Add" title="@DashboardResource.StringCreate" />
            <MudIconButton OnClick="OnReloadData" Icon="@Icons.Material.Outlined.Refresh" Color="Color.Secondary" title="@DashboardResource.StringReload" />
            <MudIconButton OnClick="OpenSearchDialog" Icon="@Icons.Material.Filled.ManageSearch" Color="Color.Tertiary" title="@DashboardResource.StringSearch" />
        </MudToolBar>
    </MudPaper>
    <MudCard>
        <MudDivider DividerType="DividerType.FullWidth" />
        <MudCardActions>
            <MudTable ServerData="ServerData" @ref="Table"
                      Dense="@_IsTableDense" Bordered Striped Hover Virtualize FixedFooter Loading="@IsTableLoading"
                      FixedHeader="@_IsTableFixedHeader" Height="@TableHeight">
                <HeaderContent>
                    <MudTh Class="column-1x">#</MudTh>
                    <MudTh Class="column-1x"></MudTh>
                    <MudTh><MudTableSortLabel SortLabel="Name" T="GetUserViewModel">@DashboardResource.StringName</MudTableSortLabel></MudTh>
                    <MudTh><MudTableSortLabel SortLabel="UserName" T="GetUserViewModel">@DashboardResource.StringUserName</MudTableSortLabel></MudTh>
                    <MudTh><MudTableSortLabel SortLabel="PersonalCode" T="GetUserViewModel">@DashboardResource.StringPersonalCode</MudTableSortLabel></MudTh>
                    <MudTh><MudTableSortLabel SortLabel="RoleName" T="GetUserViewModel">@DashboardResource.StringRole</MudTableSortLabel></MudTh>
                    <MudTh>@DashboardResource.StringPost</MudTh>
                    <MudTh Class="column-3x">
                        <MudText Align="Align.Left">
                            <MudMenu Icon="@Icons.Material.Filled.MoreVert" Color="Color.Secondary">
                                <MudMenuItem OnClick="@(() => _IsTableDense = _IsTableDense ? false : true)">
                                    <MudSwitch @bind-Value="@_IsTableDense" Color="Color.Secondary">
                                        @DashboardResource.StringDense
                                    </MudSwitch>
                                </MudMenuItem>
                                <MudMenuItem OnClick="@(() => _IsTableFixedHeader = _IsTableFixedHeader ? false : true)">
                                    <MudSwitch @bind-Value="@_IsTableFixedHeader" Color="Color.Primary">
                                        @DashboardResource.StringFixedHeader
                                    </MudSwitch>
                                </MudMenuItem>
                                <MudMenuItem OnClick="@(() => OnScrollChanged())">
                                    <MudSwitch @bind-Value="@_IsTableScroll" Color="Color.Tertiary">
                                        @DashboardResource.StringScroll
                                    </MudSwitch>
                                </MudMenuItem>
                            </MudMenu>
                        </MudText>
                    </MudTh>
                </HeaderContent>
                <RowTemplate>
                    <MudTd Class="mud-text-align-center">@context.RowNum</MudTd>
                    <MudTd>
                        <MudAvatar Size="Size.Medium">
                            <MudImage Src="@("data:image/png;base64," + Convert.ToBase64String(context.Avatar))" />
                        </MudAvatar>
                    </MudTd>
                    <MudTd>@context.Name</MudTd>
                    <MudTd>@context.UserName</MudTd>
                    <MudTd>@context.PersonalCode</MudTd>
                    <MudTd>@context.RoleName</MudTd>
                    <MudTd>@context?.UserDepartmentsTitle</MudTd>
                    <MudTd>
                        <MudIconButton OnClick="()=>OpenDetailsDialog(context.Id)" title="@DashboardResource.StringDetails" Icon="@Icons.Material.Filled.Details" Color="Color.Primary" Size="Size.Small"></MudIconButton>
                        <MudIconButton Disabled="@(!_PermissionEdit)" OnClick="()=>OpenCrudateDialog(context.Id)" title="@DashboardResource.StringEdit" Icon="@Icons.Material.Filled.Edit" Color="Color.Success" Size="Size.Small"></MudIconButton>
                        <MudIconButton Disabled="@(!_PermissionDelete)" OnClick="()=>OpenDeleteDialog(context.Id)" title="@DashboardResource.StringDelete" Icon="@Icons.Material.Filled.Delete" Color="Color.Error" Size="Size.Small"></MudIconButton>
                    </MudTd>
                </RowTemplate>
                <NoRecordsContent>
                    <MudText>@DashboardResource.MessageNoMatchingRecordsFound</MudText>
                </NoRecordsContent>
                <LoadingContent>
                    <MudText>@DashboardResource.StringLoading</MudText>
                </LoadingContent>
                <PagerContent>
                    <MudTablePager />
                </PagerContent>
            </MudTable>
        </MudCardActions>
    </MudCard>

</MaanfeeDashboardPage>
